package com.atguigu.lease.web.admin.custom.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
public class StringToItemTypeConverter implements Converter<String , ItemType> {
    @Override
    public ItemType convert(String source) {
        //如果是1 则 返回  APARTMENT枚举 ， 如果是2  则 返回  ROOM枚举
        return Arrays.stream(ItemType.values()).filter(itemType->source.equals(""+itemType.getCode())).findFirst().orElseThrow(IllegalArgumentException::new);
    }
}
